﻿using SqlSugar;
using System.Reflection;

namespace FinancialManagement.Infrstructre
{
    public class SqlsugerDBContext
    {
       protected readonly ISqlSugarClient _sqlSugarClient;

        public SqlsugerDBContext(ISqlSugarClient sqlSugarClient)
        {
            _sqlSugarClient = sqlSugarClient;
        }

        public void CreateDatabase()
        {
            _sqlSugarClient.DbMaintenance.CreateDatabase();
            var rootPath = AppDomain.CurrentDomain.BaseDirectory;
            Type[] types = Assembly.LoadFrom(rootPath + "FinancialManagement.Domain.dll").GetTypes().Where
                (x=>x.FullName.Contains("FinancialManagement.Domain.Model")).ToArray();
            _sqlSugarClient.CodeFirst.SetStringDefaultLength(200).InitTables(types);

        }


    }
}
